pub use sea_orm::entity::prelude::*;
use sea_orm::sea_query::ForeignKeyAction;
use crate::{add_relate, booking, meeting_room, user::custom};
#[derive(Debug, Clone, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "room_status_publish")]
pub struct Model {
    /// 会议室预约日状态的ID
    #[sea_orm(primary_key)]
    pub id: i64,
    /// 会议室ID
    pub room_id: i64,
    /// 预约日
    pub day: Date,
    /// 会议室状态
    pub status: i64,
    /// 移除会议室
    #[sea_orm(default = "None")]
    pub delete_at: Option<DateTime>,
}

#[derive(Debug, Clone, Copy, EnumIter)]
pub enum Relation {
    MeetingRoom,
}

impl RelationTrait for Relation {
    fn def(&self) -> RelationDef {
        match self {
            Relation::MeetingRoom => Entity::belongs_to(meeting_room::Entity)
                .from(Column::RoomId)
                .to(meeting_room::Column::Id)
                .on_update(ForeignKeyAction::Cascade)
                .on_delete(ForeignKeyAction::Restrict)
                .into(),
        }
    }
}

add_relate! {
    meeting_room::Entity => Entity | Relation::MeetingRoom
}

impl Related<custom::Entity> for Entity {
    fn to() -> RelationDef {
        booking::Relation::Custom.def()
    }
    fn via() -> Option<RelationDef> {
        booking::Relation::BookingStatus.def().rev().into()
    }
}

impl ActiveModelBehavior for ActiveModel {}
